grammar Sql;
@header {        //一种action,定义生成的词法语法解析文件的头，当使用java的时候，生成的类需要包名，可以在这里统一定义
 package antlr.sql;
 }

query: select_clause from_clause where_caluse? EOF;

select_clause: SELECT column_list;
from_clause: FROM table_reference;
where_caluse: WHERE condition;

condition: condition AND condition
          | condition OR condition
          | '(' condition ')'
          | IDENTIFIER OPERATOR literal;

column_list: column (COMMA column)*;
column: IDENTIFIER alias?;
alias: AS IDENTIFIER?;

table_reference: IDENTIFIER alias?;
literal: NUMERIC_LITERAL | STRING_LITERAL;

OPERATOR: '=' | '!=' | '<' | '<=' | '>' | '>=';
WHERE: [Ww][Hh][Ee][Rr][Ee];
SELECT: [Ss][Ee][Ll][Ee][Cc][Tt];
FROM: [Ff][Rr][Oo][Mm];
AS: [Aa][Ss];
AND: [Aa][Nn][Dd];
OR: [Oo][Rr];
COMMA: ',';
IDENTIFIER: [a-zA-Z_][a-zA-Z_0-9]*;
NUMERIC_LITERAL: [0-9]+;
STRING_LITERAL: '\'' .*? '\'';
WS: [ \t\n\r]+ -> skip;
